package com.ada.spark.action

import org.apache.spark.{SparkConf, SparkContext}

/**
  * 作用：返回该RDD排序后的前n个元素组成的数组
  */
object Demo6_takeOrdered {
    def main(args: Array[String]): Unit = {
        //创建SparkConf
        val conf = new SparkConf().setAppName("Demo6_takeOrdered").setMaster("local[*]")
        //创建Spark上下文对象
        val sc = new SparkContext(conf)

        val rdd = sc.parallelize(Array(2, 5, 4, 6, 8, 3))

        //返回该RDD排序后的前n个元素组成的数组
        val result: Array[Int] = rdd.takeOrdered(3)

        println(result.mkString(","))
        //2,3,4
    }
}
